package uk.ac.cam.bt288.DesktopApp;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

public class LoginInterface extends JFrame{

	private static final long serialVersionUID = 1L;
	private static JLabel status = null;
	private static JLabel picLabel = null;

	LoginInterface() {
		super("Logged In");
		setSize(640,580);

		JComponent qrCode = qrPanel();
		add(qrCode, BorderLayout.NORTH);

		status = statusPanel();
		add(status, BorderLayout.SOUTH);
	}

	private JLabel statusPanel () {
		JLabel currStatus = new JLabel("Ready!");
		currStatus.setBackground(Color.GREEN);
		addBorder(currStatus, "Status");
		return currStatus;
	}

	private JComponent qrPanel () {
		BufferedImage myPicture = null;
		try {
			myPicture = ImageIO.read(new File("logged_in.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		picLabel = new JLabel(new ImageIcon( myPicture ));
		addBorder(picLabel, "Logged In");
		return picLabel;
	}

	private void addBorder(JComponent component, String title) {
		Border etch = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
		Border tb = BorderFactory.createTitledBorder(etch,title);
		component.setBorder(tb);
	}

	public void setStatus (String s) {
		status.setText(s);
	}
	public void lock () {
		BufferedImage myPicture = null;
		try {
			myPicture = ImageIO.read(new File("lock.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		picLabel.setIcon(new ImageIcon(myPicture));
	}

	public void unlock () {
		BufferedImage myPicture = null;
		try {
			myPicture = ImageIO.read(new File("logged_in.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		picLabel.setIcon(new ImageIcon(myPicture));
	}
}
